#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include "md5.h"



int main(int argc, char *argv[])
{
    char const *fpath = "/tmp/md5-test.txt";
    FILE *f = fopen(fpath, "w+");
    MD5_CTX *md5ctx = MD5_CTX_Create();
    unsigned char md5[16];
    MD5Init(md5ctx);
    srand(time(NULL));
    int i;
    int r = (rand()&0x3ff)+1024;
    char buf[64];
    for(i=0; i<r; i++) {
        sprintf(buf, "%x", rand());
        fwrite(buf, 1, strlen(buf), f);
    }
    fseek(f, 0, SEEK_SET);
    int len;
    while((len=fread(buf, 1, 64, f)) > 0) {
        MD5Update(md5ctx, (unsigned char*)buf, len);
    }
    fclose(f);
    MD5Final(md5ctx, md5);
    MD5_CTX_Destroy(md5ctx);
    for(i=0; i<16; i++) {
        printf("%02x", md5[i]);
    }
    printf("  %s\n", fpath);
    return 0;
}
